package com.zyf.service.impl;

import com.zyf.pojo.SmbmsBill;
import com.zyf.mapper.SmbmsBillMapper;
import com.zyf.pojo.SmbmsProvider;
import com.zyf.pojo.BilllAndProviderVo;
import com.zyf.service.SmbmsBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyf.service.SmbmsProviderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张忆菲
 * @since 2020-09-09
 */
@Service
public class SmbmsBillServiceImpl extends ServiceImpl<SmbmsBillMapper, SmbmsBill> implements SmbmsBillService {

    @Resource
    private SmbmsProviderService smbmsProviderService;

    @Override
    public List<BilllAndProviderVo> findAll() {

        List<SmbmsBill> bills = this.baseMapper.selectList(null);
        List<BilllAndProviderVo> list = new ArrayList<>();

        Objects.requireNonNull(bills).forEach(v1 -> {
            BilllAndProviderVo providerVo = new BilllAndProviderVo();
            BeanUtils.copyProperties(v1 , providerVo);
            Integer proId = v1.getProId();
            SmbmsProvider byId = smbmsProviderService.getById(proId);
            if (byId != null)
                BeanUtils.copyProperties(byId , providerVo );

            list.add(providerVo);
        });
        return list;
    }

    public List<BilllAndProviderVo> findAllLike(BilllAndProviderVo vo){
        return baseMapper.findAllLike(vo);
    }

    @Override
    public BilllAndProviderVo findAllVo(Integer billId) {
        return baseMapper.findAllVo(billId);
    }
}
